
//_______________________________________________________________________________________点击查询
	$(".searchBtn").click(function(){
		$(".page").val("1");
		getAjax();
	})

function getAjax(){
	var airlineCode = ($(".airlineCode").val()).toUpperCase();
	var pm = $(".pm").val();
	var status = $(".status").val();
	var pageNum = $(".page").val();
	var pageSize = $(".pageSize").val();
	if(/\((.)+?\)/.test($(".dep").val())){//获取出发机场三字码
		var dep = $(".dep").val().slice(-5).split("(")[1].split(")")[0];
	}else{
		var dep = $(".dep").val()
	}
	if(/\((.)+?\)/.test($(".arr").val())){//获取到达机场三字码
		var arr = $(".arr").val().slice(-5).split("(")[1].split(")")[0];
	}else{
		var arr = $(".arr").val()
	}
	$.ajax({
		type:"get",
		url:"../flightSchedule/api/flightList?airlineCode="+airlineCode+"&dep="+dep+"&arr="+arr+"&pageSize="+pageSize+"&pageNum="+pageNum+"&pm="+pm+"&status="+status+"&temp="+Math.random(),
		dataType:"json",
		async:false,
		success:function(data){
			$(".clear").empty();			
			var totalAmount = data.data.total;
			if(totalAmount=="0"){
				layer.msg("没有搜索到结果");
				$("#dataTable").hide();
				return false;
			}else{
				$("#dataTable").show();
			}
			totalPage = data.data.pages;
			nowPage = data.data.pageNum;
			//共多少条
			$(".totalAmount").text(totalAmount);
			//共多少页
			$(".totalPage").text(totalPage);
			//第几页
			$(".nowPage").text(nowPage);
			var list = data.data.list;
			var listLength = list.length;			
			var str = "";
			var Number = 0;
			var addDateStr="";//新增日期权限
			var chgplnStr="";//修改计划执行中权限
			var chgStpStr="";//修改计划未开始权限
			var genflgStr="";//生成航班权限
			var delflgStr="";//删除航班权限
			//__________________不能用置灰的按钮
			var disChgStpStr = "";
			var disGenflgStr = "";
			var disDelflgStr = "";
			if($(".addDateBtn").val()=="1"){
				addDateStr+="<span class='createDate f00aa99'>新增日期</span>";	
			}
			if($(".chgplnBtn").val()=="1"){
				chgplnStr+="<span title=修改计划 class='changePlanO iconfont'>&#xe681;</span>";
				chgStpStr+="<span title=修改计划 class='changePlan iconfont'>&#xe681;</span>";
				disChgStpStr+="<span title=修改计划 class='iconfont aaaaaa disChange'>&#xe681;</span>";				
			}
			if($(".genflgt").val()=="1"){
				genflgStr+="<span title=生成航班 class='flightBorn iconfont'>&#xe695;</span>";
				disGenflgStr+="<span title=生成航班 class='iconfont aaaaaa disBorn'>&#xe695;</span>";
			}
			if($(".delflgt").val()=="1"){
				delflgStr+="<span title=删除 class='delete iconfont'>&#xe606; </span>";
				disDelflgStr+="<span title=删除 class='iconfont aaaaaa disDel'>&#xe606; </span>";
			}
			for(var i=0;i<listLength;i++){
				Number++;
				str+="<tr>" +
						"<td class=NumberTd colspan=6><span class='Number aaaaaa'>"+addZero(Number)+"</span><span class='aaaaaa'>航班号：</span><span class='flightNo'>"+list[i].airlineCode+"</span></td>" +						
						"<td>"+addDateStr+"<span style=display:none; class=postAirlineCode>"+list[i].airlineCode+"</span></td>" +
					 "</tr>"
				for(var j=0;j<list[i].legs.length;j++){					
					if(list[i].legs[j].status=="O"){
						var doStr = chgplnStr+disGenflgStr+"<span class=schFltId>"+list[i].legs[j].schFltId+"</span>"+delflgStr;
					}
					if(list[i].legs[j].status=="U"){
						var doStr =chgStpStr+genflgStr+delflgStr+"<span class=schFltId>"+list[i].legs[j].schFltId+"</span>"
					}
					if(list[i].legs[j].status=="D"){
						var doStr = "<span class=schFltId>"+list[i].legs[j].schFltId+"</span>"+disChgStpStr+disGenflgStr+disDelflgStr;
					}
					if(list[i].legs[j].status=="C"){
						var doStr = "<span class=schFltId>"+list[i].legs[j].schFltId+"</span>"+disChgStpStr+disGenflgStr+disDelflgStr;
					}
					var showDetail = "<span title='详情' class='iconfont aaaaaa'>&#xe807;</span>";//当此条航班记录有减班记录时可以查看详情
					if(list[i].legs[j].chgNum>0){
						showDetail = "<span title='详情' class='iconfont show'>&#xe807;</span>";
					}
					var borderStyle = "";//每个航班记录之间的tr的border
					if(j==list[i].legs.length-1){
						borderStyle = "borderStyle";
					}
					str+="<tr class="+borderStyle+">" +
						 	"<td class='f60666 font14px'>"+list[i].legs[j].startDate+"</td>" +
						 	"<td class='f60666 font14px'>"+list[i].legs[j].endDate+"</td>" +
						 	"<td class='f60666 font14px'>"+list[i].legs[j].schedule+"</td>" +
						 	"<td><span class='segmentInfo f00aa99 font14px'>"+list[i].legs[j].segmentInfo+"<span><span style=display:none; class=schFltId>"+list[i].legs[j].schFltId+"</span></td>" +
						 	"<td class='f60666 font14px'>"+list[i].legs[j].pm+"</td>" +
						 	"<td class='statusflg font14px'>"+commomFun.flightStatusToStr(list[i].legs[j].status)+"</td>" +
						 	"<td class=doStr>"+showDetail+doStr+"</td>" +
						 "</tr>" 
				}	
					 
			}	
			$(".clear").append(str);
			/*控制不同的状态，字体颜色不同begin*/
			for(var i=0;i<$(".clear>tr").length;i++){
				if($(".statusflg").eq(i).text()=="执行中"){
					$(".statusflg").eq(i).addClass("fa2828");
				}else if($(".statusflg").eq(i).text()=="已取消"){
					$(".statusflg").eq(i).addClass("aaaaaa");
				}else if($(".statusflg").eq(i).text()=="已完成"){
					$(".statusflg").eq(i).addClass("f00aa99");
				}else if($(".statusflg").eq(i).text()=="未开始"){
					$(".statusflg").eq(i).addClass("f262929");
				}
			}
			/*控制不同的状态，字体颜色不同end*/
		}
	})
}
		
//_______________________________________________________________________________________点击增减班修改详情
	$("#dataTable").delegate(".show","click",function(){	
		var that = this;
		var schFltId = $(that).parent().find("span[class=schFltId]").text();
		var thisTr = $(that).parent().parent();	
		if($(that).attr("title")=="详情"){
			$(that).html("&#xe806;");						
			$.ajax({
				type:"get",
				url:"../flightSchedule/api/flightDetail?schFltId="+schFltId+"&temp="+Math.random(),
				async:true,
				dataType:"json",
				success:function(data){
					var data = data.data;
					if(((!data.chgeVos)||(data.chgeVos.length<1))&&((!data.crftVos)||(data.crftVos.length<1))&&((!data.timeVos)||(data.timeVos.length<1))){
						layer.msg("暂无信息",{time:1000},function(){          //对无增班，减班，机型修改，时间修改信息的航班给与提示
							
						})	
						return false;
					}
					var str = "";        //将增班，减班，机型修改，时间修改的字符串放在tbody中，
					if(data.chgeVos&&data.chgeVos.length>0){              //增减班调整详情
						for(var i=0;i<data.chgeVos.length;i++){
							var type = data.chgeVos[i].type;              //增减班状态
							var status = data.chgeVos[i].status;          //完成状态
							var doStr = "";                               //完成状态下的操作
							if(status=="U"){                              //未开始时的操作
								doStr = "<span class='align iconfont doIt'>&#xe695;</span>";
							}else{
								doStr = "<span class='align iconfont aaaaaa'>&#xe695;</span>";
							}
							var type_;
							if(type=="A"){
								type_ = "<span class='f00aa99'>增班 : </span>";
							}else{
								type_ = "<span class='f00aa99'>减班 : </span>";
							}
							str+="<tr moveProp="+data.chgeVos[i].schFltId+" class='detail'>" +
								 	 "<td class=operation>"+type_+"</td>" +	
								 	 "<td class='operationTd' colspan=5>" +							
										 "<span>开始日期：<span class='f00aa99'>"+data.chgeVos[i].startDate+"</span></span>" +
										 "<span>结束日期：<span class='f00aa99'>"+data.chgeVos[i].endDate+"</span></span>" +
										 "<span>间隔时间：<span class='f00aa99'>"+data.chgeVos[i].intval+"</span></span>" +
										 "<span>状态：<span class='mockStatus'>"+commomFun.flightStatusToStr(data.chgeVos[i].status)+"</span></span>" +
										 "<span>备注：<span>"+data.chgeVos[i].remark+"</span></span>" +
								     "</td>" +
								     "<td>"+doStr+"<span class=schChgeId style=display:none;>"+data.chgeVos[i].id+"</span><span class=schChgeType style=display:none;>"+data.chgeVos[i].type+"</span></td>" +
						         "</tr>" 
						}
					}
					if(data.crftVos&&data.crftVos.length>0){           //机型调整详情
						for(var i=0;i<data.crftVos.length;i++){
							var total = (data.crftVos[i].fseat-0)+(data.crftVos[i].cseat-0)+(data.crftVos[i].yseat-0);
							var status = data.crftVos[i].status;          //完成状态
							var doStr = "";                               //完成状态下的操作
							if(status=="U"){                              //未开始时的操作
								doStr = "<span class='align iconfont doIt'>&#xe695;</span>";
							}else{
								doStr = "<span class='align iconfont aaaaaa'>&#xe695;</span>";
							}
							str+="<tr moveProp="+data.crftVos[i].schFltId+" class='detail'>" +
									"<td class='operation f00aa99'>机型修改：</td>" +
									"<td class='operationTd' colspan=5>" +								
										"<span>开始日期：<span class='f00aa99'>"+data.crftVos[i].startDate+"</span></span>" +
										"<span>结束日期：<span class='f00aa99'>"+data.crftVos[i].endDate+"</span></span>" +
										"<span>航班机型：<span>"+data.crftVos[i].aircrftName+"</span></span>" +
										"<span>头等舱座位数：<span>"+data.crftVos[i].fseat+"</span></span>" +
										"<span>商务舱座位数：<span>"+data.crftVos[i].cseat+"</span></span>" +
										"<span>经济舱座位数：<span>"+data.crftVos[i].yseat+"</span></span>" +
										"<span>座位总数：<span>"+total+"</span></span>" +
										"<span>状态：<span class='mockStatus'>"+commomFun.flightStatusToStr(data.crftVos[i].status)+"</span></span>" +
										"<span>备注：<span>"+data.crftVos[i].remark+"</span></span>" +
									"</td>" +
									"<td>"+doStr+"<span class=schChgeId style=display:none;>"+data.crftVos[i].id+"</span><span class=schChgeType style=display:none;>P</span></td>" +
						         "</tr>" 
						}
					}
					if(data.timeVos&&data.timeVos.length>0){      //航节调整详情
						for(var i=0;i<data.timeVos.length;i++){			
							var status = data.timeVos[i].status;          //完成状态
							var doStr = "";                               //完成状态下的操作
							if(status=="U"){                              //未开始时的操作
								doStr = "<span class='align iconfont doIt'>&#xe695;</span>";
							}else{
								doStr = "<span class='align iconfont aaaaaa'>&#xe695;</span>";
							}
							str+="<tr moveProp="+data.timeVos[i].schFltId+" class='detail'>" +
									"<td class='operation f00aa99'>时间修改：</td>" +
									"<td class='operationTd' colspan=5>" +								
										"<span>开始日期：<span class='f00aa99'>"+data.timeVos[i].startDate+"</span></span>" +
										"<span>结束日期：<span class='f00aa99'>"+data.timeVos[i].endDate+"</span></span>" +
										"<span>出发：<span>"+data.timeVos[i].dep+"/出发时间："+data.timeVos[i].depTime+"</span></span>" +
										"<span>到达：<span>"+data.timeVos[i].arr+"/到达时间："+data.timeVos[i].arrTime+"</span></span>" +
										"<span>状态：<span class='mockStatus'>"+commomFun.flightStatusToStr(data.timeVos[i].status)+"</span></span>" +
										"<span>备注：<span>"+data.timeVos[i].remark+"</span></span>" +
									"</td>" +
									"<td>"+doStr+"<span class=schChgeId style=display:none;>"+data.timeVos[i].id+"</span><span class=schChgeType style=display:none;>T</span></td>" +
						         "</tr>" 
						}
					}
					$(thisTr).after(str).addClass("borderStyle");					
					$(that).attr("title","收起");
				}			
			})
		}else{
			var schFltId = $(that).parent().find("span[class=schFltId]").text();
			$("tr[moveProp="+schFltId+"]").remove();
			$(thisTr).removeClass("borderStyle");
			$(that).html("&#xe807;");
			$(that).attr("title","详情");
		}						
	})
//_______________________________________________________________________________________点击增减班、时间修改、机型修改
		$(".clear").delegate(".doIt","click",function(){
			var that = this;
			var schChgeId = $(this).parent().find("span[class=schChgeId]").text();
			var schChgeType = $(this).parent().find("span[class=schChgeType]").text();
			layer.confirm('确认生效？', {
				title:['温馨提示','background-color:#6d6e72;color:#fff;font-size:14px;'],
				shade: [0.9,'#cfcfcf']
			}, function(){
				layer.msg('生效中...', {icon: 16,shade: 0.01,time:100000});
				$.ajax({
					type:"get",
					url:"../flightSchedule/api/generateFltChge?schChgeId="+schChgeId+"&type="+schChgeType+"&temp="+Math.random(),
					async:true,
					dataType:"json",
					success:function(data){		
						if(data.status=="1001"){
							layer.msg('生效成功', {icon: 1,time:1000},function(){
								$(that).removeClass("doIt").addClass("aaaaaa");
								$(that).parent().parent().find(".mockStatus").text("执行中");
							});							
						}else{				
							layer.confirm(data.message, {
								title:['生效失败','background-color:#6d6e72;color:#fff;font-size:14px;'],
								shade: [0.9,'#cfcfcf'],
							   	btn: ['确定'] //按钮
							}, function(){
								layer.closeAll('dialog');
							});								
						}							
					}			
				});						
			});						
		})
		
	
	
	
//_______________________________________________________________________________________点击航节详情
		$(".clear").delegate(".segmentInfo","click",function(){
			var schFltId = $(this).parent().find("span[class=schFltId]").text();
			layer.open({
				type: 2,
				title: ['航班详情','background-color:#6d6e72; color:#fff;font-size:14px;'],
				shadeClose: true,
				shade: [0.9,'#cfcfcf'],				
				area: ['950px', '400px'],  
				content: ['../ak/flightManageDetail.html?schFltId='+schFltId],// iframe的url，no代表不显示滚动条
				end:function(){
					getAjax();
				}				
			});		
		})
//_______________________________________________________________________________________新建航班
		$(".newSeriesBtn").click(function(){
			layer.open({
				type: 2,
				title: ['新建航班','background-color:#6d6e72; color:#fff;font-size:14px;'],
				shadeClose: true,
				shade: [0.9,'#cfcfcf'],
				area: ['840px', '80%'],  
				content: ['../ak/createFlight.html'],// iframe的url，no代表不显示滚动条
				end:function(){
					getAjax();
				}				
			});						
		})
//_______________________________________________________________________________________新增日期
		$("#dataTable").delegate(".createDate","click",function(){
			var postAirlineCode = $(this).parent().find("span[class=postAirlineCode]").text();
			layer.open({
				  type: 2,
				  title: ['新建日期','background-color:#6d6e72; color:#fff;font-size:14px;'],
				  shadeClose: true,
				  shade: [0.9,'#cfcfcf'],
				  area: ['840px', '80%'],  
				  content: ['../ak/createDate.html?&postAirlineCode='+postAirlineCode],  // iframe的url，no代表不显示滚动条	
				  end:function(){
					  getAjax();
				  }
			 });			
		})
//_______________________________________________________________________________________生成航班
		$("#dataTable").delegate(".flightBorn","click",function(){
			var schFltId = $(this).parent().find("span[class=schFltId]").text();
			layer.confirm('确认生效该航线日期段信息？', {
				title:['温馨提示','background-color:#6d6e72;color:#fff;font-size:14px;'],
				shade: [0.9,'#cfcfcf']			
			}, function(){
				layer.msg('生效中...', {icon: 16,shade: 0.01});
				$.ajax({
					type:"get",
					url:"../flightSchedule/api/generateFlight?schFltId="+schFltId+"&temp="+Math.random(),
					async:true,
					dataType:"json",
					success:function(data){
						if(data.status=="1001"){
							layer.msg('已生效', {icon: 1},function(){
								getAjax();
							});
						}else{
							layer.alert('航班生成失败'+data.message, {icon: 2});
						}
					}			
				});						
			});				
		})
//_______________________________________________________________________________________航班取消	
		$("#dataTable").delegate(".delete","click",function(){
			var schFltId = $(this).parent().find("span[class=schFltId]").text();
			layer.confirm('确认取消该条航线？', {
					title:['温馨提示','background-color:#6d6e72;color:#fff;font-size:14px;'],
					shade: [0.9,'#cfcfcf']
				}, function(){
					layer.msg('取消中...', {icon: 16,shade: 0.01});
					$.ajax({
						type:"get",
						url:"../flightSchedule/api/cancel?schFltId="+schFltId+"&temp="+Math.random(),
						success:function(data){		
							data = JSON.parse(data)
							if(data.status=="1001"){
								layer.msg('取消成功', {icon: 1},function(){
									getAjax();
								});							
							}else{				
								layer.confirm(data.message, {
									title:['取消失败','background-color:#00aa98;color:#fff'],
									shade: 0.8,
								   	btn: ['确定'] //按钮
								}, function(){
									layer.closeAll('dialog');
								});								
							}							
						}			
					});						
				});				
		})
//_______________________________________________________________________________________未开始的修改计划
		$("#dataTable").delegate(".changePlan","click",function(){
			var schFltId = $(this).parent().find("span[class=schFltId]").text()			
			layer.open({
				type: 2,
				title: ['修改计划','background-color:#6d6e72; color:#fff;font-size:14px;'],
				shadeClose: true,
				shade:[0.9,'#cfcfcf'],
				area: ['840px', '80%'],  
				content: ['../ak/changePlan.html?schFltId='+schFltId],  // iframe的url，no代表不显示滚动条
				end:function(){
					getAjax();
				}	
			});						
		})
//_______________________________________________________________________________________执行中状态下的修改计划
		$("#dataTable").delegate(".changePlanO","click",function(){
			var schFltId = $(this).parent().find("span[class=schFltId]").text()	
			layer.open({
				type: 2,
				title: ['修改计划','background-color:#6d6e72; color:#fff;font-size:14px;'],
				shadeClose: true,
				shade: [0.9,'#cfcfcf'],
				area: ['840px', '80%'],  
				content: ['../ak/changePlanO.html?schFltId='+schFltId],  // iframe的url，no代表不显示滚动条
				end:function(){
					getAjax();
				}	
			});						
		})		



//____________________________________________________________________________________表头固定
	$("#dataTable").freezeHeader();		
//____________________________________________________________________________________分页
	$(".Pagination").load("Pagination.html",function(){
		getAjax()
	})
//____________________________________________________________________________________城市交换
	$(".exchangeAirportCode").click(function(){
		var exchangeVar = $(".dep").val();
		$(".dep").val($(".arr").val());
		$(".arr").val(exchangeVar);
	})				
//____________________________________________________________________________________机场		
var autocompleteData=[];
$.ajax({
	type:"get",
	url:"../Airapt?pageSize=100000&pageNum=1&temp="+Math.random(),
	dataType:"json",
	success:function(data){	
		autocompleteData = data.data.list; 
		$('.autocomplete').autocomplete({
		    lookup: autocompleteData,
		    autoSelectFirst:true,
		    onSelect: function (suggestion) {		   
		    }
		});
	}
})	





	
	
